﻿
function afterLoadComplete(postUrl, columnName, imageUrl, actionMethod, dialogTitle) {
    var ids = this.getDataIDs();
    var grid = this;

    $.each(this[0].p.colModel, function (i) {
        if (this.name == columnName) {
            var column = this;
            var clientData = this.clientData;

            $.each(ids, function (i, name) {
                var rowId = this;
                var link = postUrl + "?id=" + rowId;

                var stringFunc = 'return false;';
                if (!!actionMethod && actionMethod != '') {
                    var stringFunc = actionMethod + '("' + grid.selector + '",' + rowId + ',"' + link + '","' + dialogTitle + '");' + stringFunc;
                }

                var html = "<a href='#' onclick='" + stringFunc + "'><img class='img-grid'" + " src='" + imageUrl + "'/></a>";

                var rowData = {};
                rowData[column.name] = html;
                grid.setRowData(this, rowData);
            })
        }
    })
}

function afterClickEdit(gridId, rowId, posturl, caption) {
    if (!!gridId) {

        $(gridId).editGridRow(rowId, {
            reloadAfterSubmit: true,
            url: posturl,
            editCaption: caption,
            modal: true,
            closeAfterEdit: true,
            afterSubmit: processErrorAfterSubmit
        });
    }
    else
        alert("Please Select Row");
}

function afterClickDelete(gridId, rowId, posturl, caption) {
    if (!!gridId)
        $(gridId).delGridRow(rowId, {
            reloadAfterSubmit: true,
            url: posturl,
            caption: caption
        });
    else
        alert("Please Select Row");
}

function processErrorAfterSubmit(response, postdata) {
    var data = null;
    if (response.responseText != '') {
        data = $.parseJSON(response.responseText);
    }

    if (data == null) {
        return [true, '', ''];
    }

    return [data.success, data.message];
}
